import requests
import unittest

class Test_ihrmadd(unittest.TestCase):
    def test_bixuan(self):
        resp_login = requests.post(url="http://ihrm2-test.itheima.net/api/sys/login",
                                   headers={"Content-Type": "application/json"},
                                   json={"mobile":"13800000002",
                                         "password":"123456"})
        token = "Bearer " + resp_login.json().get("data")

        resp_tianjia = requests.post(url="http://ihrm2-test.itheima.net/api/sys/user",
                                     headers={"Content-Type":"application/json",
                                              "Authorization":token},
                                     json={"username":"张三的",
                                           "mobile":"15678779932",
                                           "workNumber":"34669923"})
        self.assertEqual(200,resp_tianjia.status_code)
        self.assertEqual(True,resp_tianjia.json().get("success"))
        self.assertEqual(10000,resp_tianjia.json().get("code"))
        self.assertIn("成功",resp_tianjia.json().get("message"))

    def test_quanxuan(self):
        resp_login = requests.post(url="http://ihrm2-test.itheima.net/api/sys/login",
                                   headers={"Content-Type": "application/json"},
                                   json={"mobile":"13800000002",
                                         "password":"123456"})
        token = "Bearer " + resp_login.json().get("data")

        resp_tianjia = requests.post(url="http://ihrm2-test.itheima.net/api/sys/user",
                                     headers={"Content-Type":"application/json",
                                              "Authorization":token},
                                     json={"username":"张三ba",
                                           "mobile":"13456786644",
                                           "workNumber":"12344444",
                                           "timeOfEntry":"2022-09-01",
                                           "ormOfEmployment ":"2",
                                           "departmentId":"1066240656666454344",
                                           "correctionTime ":"2022-10-01"})
        self.assertEqual(200,resp_tianjia.status_code)
        self.assertEqual(True,resp_tianjia.json().get("success"))
        self.assertEqual(10000,resp_tianjia.json().get("code"))
        self.assertIn("成功",resp_tianjia.json().get("message"))

    def test_bijiafei(self):
        resp_login = requests.post(url="http://ihrm2-test.itheima.net/api/sys/login",
                                   headers={"Content-Type": "application/json"},
                                   json={"mobile":"13800000002",
                                         "password":"123456"})
        token = "Bearer " + resp_login.json().get("data")

        resp_tianjia = requests.post(url="http://ihrm2-test.itheima.net/api/sys/user",
                                     headers={"Content-Type":"application/json",
                                              "Authorization":token},
                                     json={"username":"张三四",
                                            "mobile":"15672254566",
                                            "workNumber":"34222566",
                                            "timeOfEntry":"2022-09-01",
                                            "ormOfEmployment ":"2"})
        self.assertEqual(200,resp_tianjia.status_code)
        self.assertEqual(True,resp_tianjia.json().get("success"))
        self.assertEqual(10000,resp_tianjia.json().get("code"))
        self.assertIn("成功",resp_tianjia.json().get("message"))

    def test_shaocan(self):
        resp_login = requests.post(url="http://ihrm2-test.itheima.net/api/sys/login",
                                   headers={"Content-Type": "application/json"},
                                   json={"mobile":"13800000002",
                                         "password":"123456"})
        token = "Bearer " + resp_login.json().get("data")

        resp_tianjia = requests.post(url="http://ihrm2-test.itheima.net/api/sys/user",
                                     headers={"Content-Type":"application/json",
                                              "Authorization":token},
                                     json={"username":"张三与",
                                           "mobile":"15672245965"})
        self.assertEqual(200,resp_tianjia.status_code)
        self.assertEqual(False,resp_tianjia.json().get("success"))
        self.assertEqual(20002,resp_tianjia.json().get("code"))
        self.assertIn("失败",resp_tianjia.json().get("message"))





